﻿var layer = layui.layer, form = layui.form;
/**
 * 删除
 * @@param id
 */
function deleteModel(posturl, id, backurl) {
    layer.confirm("确定要删除该项吗？", { icon: 3, title: '提示' }, function (index) {
        layer.close(index);
        $.ajax({
            url: posturl,
            type: "post",
            data: { "id": id },
            success: function (rs) {
                var iconMsg = 2;
                if (rs.status == 1) {
                    iconMsg = 1;
                }
                layer.open({
                    title: "提示",
                    icon: iconMsg,
                    content: rs.msg,
                    yes: function () {
                        layer.closeAll();
                        if (rs.status == 1) {
                            window.location.href = backurl;
                        }
                    }
                });
            },
            error: function (rs) {
                layer.msg("网络错误，删除失败！", { icon: 2 });
            }
        });
    });
}



/**
 * 表单提交
 * @@param posturl
 * @@param backurl
 */
function save(posturl, backurl) {
    //监听提交
    form.on('submit(formData)', function (data) {
        $.ajax({
            url: posturl,
            type: "post",
            data: data.field,
            success: function (rs) {
                var iconMsg = 2;
                if (rs.status==1) {
                    iconMsg = 1;
                }
                layer.open({
                    title: "提示",
                    icon: iconMsg,
                    content: rs.msg,
                    yes: function () {
                        layer.closeAll();
                        if (rs.status == 1) {
                            window.location.href = backurl;
                        }
                    }
                });
            },
            error: function (rs) {
                layer.msg("网络错误，保存失败！", {icon:2});
            }
        });
        return false;
    });
}


/**
 * 编辑
 * @param {any} url
 */
function editModel(url) {
    var height = $(window).height() + 'px';
    var width = $(window).width() + 'px';
    var array = [width, height];
    console.log(array);
    layer.open({
        type: 2,
        area: ['1284px', '640px'],
        maxmin: true,
        content: url
    });
}